import request from '@/router/axios';
import config from '@/config/website'

//所有产品列表
export const productList = (current, size, params) => {
  return request({
    url: '/api/prdinfo/page',
    method: 'get',
    params: {
      current,
      size,
      ...params
    }
  })
}

//主产品分页列表
export const masterProductList = (current, size, params) => {
  return request({
    url: '/api/prdinfo/topprdpage',
    method: 'get',
    params: {
      current,
      size,
      ...params
    }
  })
}

//所有上级产品
export const allMasterProducts = (params) => {
  return request({
    url: '/api/prdinfo/listLeaderPrd',
    method: 'get',
    params: {
      ...params
    }
  })
}

// 根据产品图号获取上级产品下拉选
export const getDirectLeaders = (params) => {
  return request({
    url: '/api/prdinfo/listLeaderPrd',
    method: 'get',
    params: {
      ...params
    }
  })
}
//主产品列表
export const masterProducts = (params) => {
  return request({
    url: '/api/prdinfo/listByName',
    method: 'get',
    params: {
      ...params
    }
  })
}

//新增产品
export const productAdd = (data) => {
  return request({
    url: '/api/prdinfo/save',
    method: 'post',
    data: data
  })
}
//编辑产品
export const productUpdate = (data) => {
  return request({
    url: '/api/prdinfo/update',
    method: 'post',
    data: data
  })
}

//获取产品详情
export const productDetail = (id) => {
  return request({
    url: '/api/prdinfo/detail',
    method: 'get',
    params: {
      id
    }
  })
}

//删除产品
export const removeproduct = (ids, productDrawingNos) => {
  return request({
    url: '/api/prdinfo/remove',
    method: 'post',
    params: {
      ids, productDrawingNos
    }
  })
}
//bom 列表
export const bomList = (current, size, params) => {
  return request({
    url: '/api/prdbom/page',
    method: 'get',
    params: {
      current,
      size,
      ...params
    }
  })
}
//所有有BOM的产品列表
export const bomproductList = (params) => {
  return request({
    url: '/api/prdinfo/bomPrdSelected',
    method: 'get',
    params: {
      ...params
    }
  })
}
//所有有BOM的设备列表
export const bomEquipmentList = (params) => {
  return request({
    url: '/api/equipmentinfo/findAll',
    method: 'get',
    params: {
      ...params
    }
  })
}
//产品BOM列表
export const productBomList = (productNo) => {
  return request({
    url: '/api/prdbom/bomTreeByPrdNo',
    method: 'get',
    params: {
      productNo
    }
  })
}
// 产品BOM状态
export const productBomStatus = (productNo) => {
  return request({
    url: '/api/prdbom/getBomStatus',
    method: 'get',
    params: {
      productNo
    }
  })
}
//新增产品bom
export const bomAdd = (data) => {
  return request({
    url: '/api/prdbom/save',
    method: 'post',
    data: data
  })
}
// 新增BOM子级
export const childBomAdd = (data) => {
  return request({
    url: '/api/prdbom/submit',
    method: 'post',
    data: data
  })
}

// //获取BOM子级详情
// export const childBomDetail = (id) => {
//   return request({
//     url: '/api/prdbom/getOne',
//     method: 'get',
//     params: {
//       id
//     }
//   })
// }
//获取物料类型
export const getMaterialTypeTree = (params) => {
  return request({
    url: '/api/materialinfo/getTree',
    method: 'get',
    params: {
      ...params
    }
  })
}
//编辑产品bom
export const bomUpdate = (data) => {
  return request({
    url: '/api/prdbom/update',
    method: 'post',
    data: data
  })
}

// 删除产品bom
export const bomRemove = (ids) => {
  return request({
    url: '/api/prdbom/remove',
    method: 'post',
    params: {
      ids
    }
  })
}
//获取产品详情
export const bomDetail = (id) => {
  return request({
    url: '/api/prdbom/detail',
    method: 'get',
    params: {
      id
    }
  })
}
//根据物料类型和物料组获取物料下拉选
export const materialList = (params) => {
  return request({
    url: '/api/prdinfo/materialByTypeAndGroup',
    method: 'get',
    params: {
      ...params
    }
  })
}
//产品项目列表
export const productProjectList = (productDrawingNo) => {
  return request({
    url: '/api/projectprdinfo/prjlistbyprddrawingno',
    method: 'get',
    params: {
      productDrawingNo
    }
  })
}


//产品图号对应关系列表
export const getMatchList = (current, size, params) => {
  return request({
    url: '/api/productdrawingchange/page',
    method: 'get',
    params: {
      current,
      size,
      ...params
    }
  })
}

//生产BOM 根据产品获取物料信息
export const getMaterialListByLeaderNo = (directLeaderNo) => {
  return request({
    url: '/api/prdbom/getMaterialListByLeaderNo',
    method: 'get',
    params: {
      directLeaderNo
    }
  })
}
//生产BOM 获取所有辅助材料
export const getAMList = (directLeaderNo) => {
  return request({
    url: '/api/prdbom/getAMList',
    method: 'get',
    params: {
      directLeaderNo
    }
  })
}
//新增产品图号对应关系
export const addMatch = (data) => {
  return request({
    url: '/api/productdrawingchange/save',
    method: 'post',
    data: data
  })
}
//编辑产品图号对应关系
export const updateMatch = (data) => {
  return request({
    url: '/api/productdrawingchange/save',
    method: 'post',
    data: data
  })
}

// 删除产品图号对应关系
export const removeMatch = (ids) => {
  return request({
    url: '/api/productdrawingchange/remove',
    method: 'post',
    params: {
      ids
    }
  })
}
//获取产品图号对应关系
export const getMatch = (id) => {
  return request({
    url: '/api/productdrawingchange/detail',
    method: 'get',
    params: {
      id
    }
  })
}
//配方
export const getMaterialListForFormula = () => {
  return request({
    url: '/api/materialinfo/materialList',
    method: 'get',
    params: {
      materialFlag:'M'
    }
  })
}
//工位
export const produceStationList = () => {
  return request({
    url: '/api/produceStation/list',
    method: 'get',
  })
}
//工位
export const updateStatus = (data) => {
  return request({
    url: '/api/prdbom/updateStatus',
    method: 'post',
    data:data,
  })
}
